#include <stdio.h>
#include "pub_header.h"

#define Swap16(A) ((((uint16)(A) & 0XFF00) >> 8)|((uint16)(A) & 0X00FF << 8))
#define Swap32(A) ((((uint32)(A) & 0XFF000000) >> 24) | \
                                  (((uint32)(A) & 0X00FF0000) >>   8) | \
                                  (((uint32)(A) & 0X0000FF00) <<   8) | \
                                  (((uint32)(A) & 0X000000FF) << 24))
                                  
static union 
{
        char c[4];
        unsigned long mylong;
}endian_test = {{'l','?','?','b'}};

#define ENDIANNESS ((char)endian_test.mylong)

uint16 l_htons(uint16 hs)
{
        return (ENDIANNESS == 'l')?Swap16(hs):hs;
}

uint32 l_htonl(uint32 hl)
{
        return (ENDIANNESS == 'l')?Swap32(hl):hl;
}

uint16 l_ntohs(uint16 ns)
{
        return (ENDIANNESS == 'l')?Swap16(ns):ns;
}

uint32 l_ntohl(uint32 nl)
{
        return (ENDIANNESS == 'l')?Swap32(nl):nl;
}
